LauncherGroupTest = TestCase("Test Launcher Groups");

var physicsInfo = {
		gravity : 9.81
	};

LauncherGroupTest.prototype.testSameHeight = function(){	
	var placement = {
		pattern : ["xxxx"],
		y : 5,
		startTime : 1.0,
		pace : 1.0,
		vSpacing : 1,
		launchers : 4
	};
	launcherGroup = new LauncherGroup(placement, physicsInfo);
	isValid(launcherGroup, placement);
};

LauncherGroupTest.prototype.testMultipleProjectiles = function(){	
	var placement = {
		pattern : ["x"+
		           "x"+
		           "x"+
		           "x"],
		y : 5,
		startTime : 1.0,
		pace : 1.0,
		vSpacing : 1,
		launchers : 1
	};
	launcherGroup = new LauncherGroup(placement, physicsInfo);
	isValid(launcherGroup, placement);
};


LauncherGroupTest.prototype.testProjectileGrid = function(){	
	var placement = {
		pattern : ["xxxx"+
		           "x  x"+
		           "x  x"+
		           "xxxx"],
		y : 5,
		startTime : 1.0,
		pace : 1.0,
		vSpacing : 1,
		launchers : 4
	};
	launcherGroup = new LauncherGroup(placement, physicsInfo);
	isValid(launcherGroup, placement);
};

LauncherGroupTest.prototype.testMultipleProjectileGrids = function(){	
	var placement = {
		pattern : 
				  ["xxxx"+
		           "x  x"+
		           "x  x"+
		           "xxxx",
		           
		           "x  x"+
		           " xx "+
		           " xx "+
		           "x  x"],
		y : 5,
		startTime : 1.0,
		pace : 1.0,
		vSpacing : 1,
		launchers : 4
	};
	launcherGroup = new LauncherGroup(placement, physicsInfo);
	isValid(launcherGroup, placement);
};

LauncherGroupTest.prototype.testMultipleProjectileGridsOddTiming = function(){	
	var placement = {
		pattern : 
				  ["xxxx"+
		           "x  x"+
		           "x  x"+
		           "xxxx",
		           
		           "x  x"+
		           " xx "+
		           " xx "+
		           "x  x"],
		y : 8.7,
		startTime : 2.4,
		pace : 2.1,
		vSpacing : 1.5,
		launchers : 4
	};
	launcherGroup = new LauncherGroup(placement, physicsInfo);
	isValid(launcherGroup, placement);
};



function isValid(launcherGroup, placement){
	curYs = new Array(placement.launchers);
	for(i=0;i<curYs.length;i++)
		curYs[i] = 0;
	for(p=0;p<placement.pattern.length;p++){
		for(strPos=0;strPos<placement.pattern[p].length;strPos++){
			if(placement.pattern[p][strPos] == "x"){
				x = strPos % placement.launchers;
				y = Math.floor(strPos / placement.launchers);
				assertVeryClose("Pattern "+p+", Launcher "+x+", Projectile "+y+" is wrong height:",
						placement.y - placement.vSpacing * y,
						launcherGroup.launchers[x].projectiles[curYs[x]].getYPosition(placement.startTime + placement.pace * p));
				curYs[x]++;
			}
		}
	}
}

function assertVeryClose(val1, val2) {
	if(Math.abs(val1 - val2) > 0.01)
		fail();
}